package edu.mju.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.mju.educms.entity.CmsBanner;
import edu.mju.educms.mapper.CmsBannerMapper;
import edu.mju.educms.service.CmsBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author xiaoxin
 * @since 2020-09-20
 */
@Service
public class CmsBannerServiceImpl extends ServiceImpl<CmsBannerMapper, CmsBanner> implements CmsBannerService {

    /**
     * 查询所有banner
     * @return list集合
     *
     * Cacheable:Spring Boot的缓存注解
     * 存入Redis中：banner::selectIndexList
     */
    @Cacheable(key = "'selectIndexList'",value = "banner")
    @Override
    public List<CmsBanner> selectAllBanner() {
        //根据创建时间进行排序，显示排列后的前2条记录
        QueryWrapper<CmsBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        wrapper.last("limit 2");
        List<CmsBanner> list = baseMapper.selectList(wrapper);
        return list;
    }
}
